package com.chixing.ih.module.admin.controller;

import com.chixing.ih.json.ResponseData;
import com.chixing.ih.module.admin.pojo.dto.OrderUserTaskDTO;
import com.chixing.ih.module.admin.service.IAdminOrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("AOC")
@Api(tags = "管理员订单相关Api")
public class AdminOrderCon {

    @Autowired
    private IAdminOrderService adminOrderService;

    @ApiOperation(value = "查看等待结算订单接口", notes = "查看等待结算订单数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = true, dataType = "String")

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("settlementingOrder")
    public Map<String, Object> getSettlementingOrder(Integer pageNum, Integer pageSize, String keyword) {
        List<OrderUserTaskDTO> settlementingOrder = adminOrderService.getSettlementingOrder(pageNum, pageSize, keyword);
        PageInfo<OrderUserTaskDTO> info = new PageInfo<>(settlementingOrder);
        return ResponseData.REP_GET_SUCCESS(info);
    }


    @ApiOperation(value = "查看等待退款订单接口", notes = "查看等待退款订单数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = true, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("refusingOrder")
    public Map<String, Object> getRefusingOrder(Integer pageNum, Integer pageSize, String keyword) {
        List<OrderUserTaskDTO> refusingOrder = adminOrderService.getRefusingOrder(pageNum, pageSize, keyword);
        PageInfo<OrderUserTaskDTO> info = new PageInfo<>(refusingOrder);
        return ResponseData.REP_GET_SUCCESS(info);
    }


    @ApiOperation(value = "查看已结算的订单接口", notes = "查看管理员同意结算的订单数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数", required = true, dataType = "Integer")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("getCompletedOrder")
    public Map<String, Object> getCompletedOrder(Integer pageNum, Integer pageSize) {
        List<OrderUserTaskDTO> completedOrder = adminOrderService.getCompletedOrder(pageNum, pageSize);
        PageInfo<OrderUserTaskDTO> info = new PageInfo<>(completedOrder);
        return ResponseData.REP_GET_SUCCESS(info);
    }

    @ApiOperation(value = "查看已退款订单接口", notes = "查看待管理员同意退款的订单数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数", required = true, dataType = "Integer")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
    })
    @GetMapping("getRefundedOrder")
    public Map<String, Object> getRefundedOrder(Integer pageNum, Integer pageSize) {
        List<OrderUserTaskDTO> refundedOrder = adminOrderService.getRefundedOrder(pageNum, pageSize);
        PageInfo<OrderUserTaskDTO> info = new PageInfo<>(refundedOrder);
        return ResponseData.REP_GET_SUCCESS(info);
    }

    @ApiOperation(value = "同意结算", notes = "同意申请结算的订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单Id", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "taskId", value = "任务Id", required = true, dataType = "Integer")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功"),
    })
    @GetMapping("agreeToSettlement")
    public boolean agreeToSettlement(Integer orderId, Integer taskId) {
        return adminOrderService.agreeToSettlement(orderId, taskId);
    }

    @ApiOperation(value = "同意退款", notes = "同意申请退款的订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单Id", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "taskId", value = "任务Id", required = true, dataType = "Integer")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功"),
    })
    @GetMapping("agreeToRefund")
    public boolean agreeToRefund(Integer orderId, Integer taskId) {
        return adminOrderService.agreeToRefund(orderId, taskId);
    }

    @ApiOperation(value = "查看所有订单", notes = "查看所有状态的订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示条数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = true, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查看成功"),
    })

    @GetMapping("getAllOrder")
    public Map<String, Object> getAllOrder(Integer pageNum, Integer pageSize,String keyword) {
        List<OrderUserTaskDTO> allOrder = adminOrderService.getAllOrder(pageNum, pageSize,keyword);
        PageInfo<OrderUserTaskDTO> info = new PageInfo<>(allOrder);
        return ResponseData.REP_GET_SUCCESS(info);
    }


}
